﻿#include "TreeWidgetProp.h"
#include "TreeItemTypes.h"
#include "OperatorsInterface/TreeEventOperator.h"
#include <QTreeWidgetItem>

namespace GUI
{
    TreeWidgetProp::TreeWidgetProp(QWidget* parent /*= nullptr*/)
        :TreeWidgetPage(parent)
    {
        this->blockSignals(true);
        this->initTree();
        this->expandAll();
        this->blockSignals(false);
    }

    TreeWidgetType TreeWidgetProp::getTreeWidgetType()
    {
        return PageProp;
    }

    void TreeWidgetProp::initTree()
    {
        //材料树根节点
        QTreeWidgetItem* matTreeRoot = new QTreeWidgetItem(this, (int)(PropTreeItemsType::PTMaterialRoot));
        matTreeRoot->setText(0, tr("Material"));
        matTreeRoot->setIcon(0, QIcon(""));
        this->addTopLevelItem(matTreeRoot);
        //材料各种类型子节点
        this->CreateTreeItem(matTreeRoot, tr("Fluids"), (int)PTMatFluids);
        this->CreateTreeItem(matTreeRoot, tr("Isotropic Solids"), (int)PTMatIsoSolid);
        this->CreateTreeItem(matTreeRoot, tr("Visco-Elastic Solids"), (int)PTMatViscoElastic);
        this->CreateTreeItem(matTreeRoot, tr("Foams"), (int)PTMatFoam);
        this->CreateTreeItem(matTreeRoot, tr("Fibers"), (int)PTMatFiber);
        this->CreateTreeItem(matTreeRoot, tr("FE Material Cards [MID]"), (int)PTMatFEMaterial);

        //属性树根节点
        QTreeWidgetItem* ppTreeRoot = new QTreeWidgetItem(this, (int)(PropTreeItemsType::PTPhysicalPropRoot));
        ppTreeRoot->setText(0, tr("Physical Properties"));
        ppTreeRoot->setIcon(0, QIcon(""));
        this->addTopLevelItem(ppTreeRoot);
        //梁节点
        this->CreateTreeItem(ppTreeRoot, tr("Beams"), (int)PTPPBeam);
        //板壳类型子节点
        QTreeWidgetItem* shellRoot = this->CreateTreeItem(ppTreeRoot, tr("Plates & Shells"), (int)PTPPPlatShellsRoot);
        this->CreateTreeItem(shellRoot, tr("Uniform"), (int)PTPPShellUniform);
        this->CreateTreeItem(shellRoot, tr("General Laminate"), (int)PTPPShellGeneralLaminate);
        this->CreateTreeItem(shellRoot, tr("Ribbed"), (int)PTPPShellRibbed);
        //FE属性
        this->CreateTreeItem(ppTreeRoot, tr("FE Property Cards [PID]"), (int)PTPPFEProperty);
        //声学包根节点
        QTreeWidgetItem* nctTreeRoot = new QTreeWidgetItem(this, (int)(PropTreeItemsType::PTNCTRoot));
        nctTreeRoot->setText(0, tr("Noise Control Treatment"));
        nctTreeRoot->setIcon(0, QIcon(""));
        this->addTopLevelItem(nctTreeRoot);
        this->CreateTreeItem(nctTreeRoot, tr("Treatment Lay-Up"), (int)PTNCTLayUp);
        this->CreateTreeItem(nctTreeRoot, tr("User Define Treatment"), (int)PTNCTUserDef);
        this->CreateTreeItem(nctTreeRoot, tr("Multiple Noise Control Treatment"), (int)PTNCTMultiple);
        //频谱根节点
        QTreeWidgetItem* specTreeRoot = new QTreeWidgetItem(this, (int)(PropTreeItemsType::PTSpectraRoot));
        specTreeRoot->setText(0, tr("Spectra"));
        specTreeRoot->setIcon(0, QIcon(""));
        this->addTopLevelItem(specTreeRoot);
        //阻尼
        this->CreateTreeItem(specTreeRoot, tr("Damping Loss Factor"), (int)PTSDamping);
        this->CreateTreeItem(specTreeRoot, tr("Absorption Coefficient"), (int)PTSAbsorption);
        //统计能量
        this->CreateTreeItem(specTreeRoot, tr("Modal Density"), (int)PTSModalDensity);
        this->CreateTreeItem(specTreeRoot, tr("Wavenumber"), (int)PTSWavenumber);
        this->CreateTreeItem(specTreeRoot, tr("Coupling Loss Factor"), (int)PTSCoupling);
        //传递系数
        this->CreateTreeItem(specTreeRoot, tr("Transmission Loss"), (int)PTSTransmissionLoss);
        this->CreateTreeItem(specTreeRoot, tr("Insertion Loss"), (int)PTSInsertionLoss);
        this->CreateTreeItem(specTreeRoot, tr("Shear Modulus"), (int)PTSShearModulus);
        //载荷数据
        this->CreateTreeItem(specTreeRoot, tr("Velocity"), (int)PTSVelocity);
        this->CreateTreeItem(specTreeRoot, tr("Angular Velocity"), (int)PTSAnlrVelocity);
        this->CreateTreeItem(specTreeRoot, tr("Acceleration"), (int)PTSAcceleration);
        this->CreateTreeItem(specTreeRoot, tr("Force"), (int)PTSForce);
        this->CreateTreeItem(specTreeRoot, tr("Moment"), (int)PTSMoment);
        this->CreateTreeItem(specTreeRoot, tr("Pressure"), (int)PTSPressure);
        this->CreateTreeItem(specTreeRoot, tr("Energy"), (int)PTSEnergy);
        this->CreateTreeItem(specTreeRoot, tr("Power"), (int)PTSPower);
    }

    void TreeWidgetProp::on_itemClicked(QTreeWidgetItem *item, int column)
    {
        Oper::TreeEventOperator* toper = this->getOperatorT<Oper::TreeEventOperator>("OperPropTreeEvent");
        if (toper == nullptr)return;
        toper->itemClicked(item, column);
    }

    void TreeWidgetProp::on_itemDoubleClicked(QTreeWidgetItem *item, int column)
    {
        Oper::TreeEventOperator* toper = this->getOperatorT<Oper::TreeEventOperator>("OperPropTreeEvent");
        if (toper == nullptr)return;
        toper->itemDouleClicked(item, column);
    }

}


